
CV.Tree.QuickToolbar = new Class({
    Implements: Options,
    options:{
        buttons: [
            { action: 'add', icon: 'imgs/add.png', title: 'Add a child node' },
            { action: 'rename', icon: 'imgs/rename.png', title: 'Rename this node' },
            { action: 'remove', icon: 'imgs/remove.png', title: 'Delete this node' }
        ],
        fade: true
    },
    initialize: function(tree, options) {
        this.tree = tree;
        this.setOptions(options);
        this.tree.addEvent('select', this.show.bind(this));
        this.tree.addEvent('unSelect', this.hide.bind(this));
    },
    show: function(node) {

        var wrapper = node.getDOM('wrapper');
        var miniToolbar = wrapper.getElement('.cv-tree-quicktoolbar');
        if(!miniToolbar) {
            var miniButtons = [];

            this.options.buttons.each(function(item) {
                miniButtons.push(new Element('img.cv-tree-quicktoolbar-button.cv-tree-quicktoolbar-button-' + item.action + '[title=' + item.title + ']', {
                    'alt': '[' + item.title + ']',
                    'src': item.icon,
                    'events': {
                        'click': (function(e) {
                            e.stop();
                            this.tree.fireEvent('action', [item.action, node]);
                        }).bind(this)
                    }
                }));
            }, this);

            miniToolbar = new Element('span.cv-tree-quicktoolbar');
            miniToolbar.adopt(miniButtons);
            miniToolbar.fade('hide');
            wrapper.grab(miniToolbar);
        }
        miniToolbar.fade(this.options.fade ? 'in' : 'show');
    },
    hide: function(node) {
        var wrapper = node.getDOM('wrapper');
        var miniToolbar = wrapper.getElement('.cv-tree-quicktoolbar');
        if(miniToolbar) {
            miniToolbar.fade(this.options.fade ? 'out' : 'hide');
        }
    }
});
